from PIL import Image, ImageDraw, ImageFont
import os

# 设置字体文件路径
font_path = 'cmex10.ttf'
font_size = 36
font = ImageFont.truetype(font_path, font_size)

# 循环遍历Unicode字符
# for code_point in range(0x2200, 0x22FF):  # 数学运算符的Unicode范围
try:
    # 尝试渲染字符
    # char = chr(code_point)
    char = "X"
    img = Image.new('RGB', (100, 100), color=(73, 109, 137))
    d = ImageDraw.Draw(img)
    d.text((5, 5), char, fill=(255, 255, 0), font=font)

    # 显示或保存图像
    img.show()
    # 或者保存到文件
    img.save(f'char_X.png')

    # print(f"Character: {char}, Unicode: U+{hex(code_point)[2:].upper()}")
except OSError:
    # 忽略无法渲染的字符
    pass